/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package conversation;

import junit.framework.Assert;

public class FakeInstrumentationExample {
	
	public void instrumentationExample(Verify verify) {
		verify.that(123)
			.isGreaterThan(100);

		verify.that(123)
			.isGreaterThan(100)
			.because("blah blah");
	}
	
	
	
	
	public void instrumentationExample_expanded(Verify verify) {
																					Reflection.conversationLength(2);
		IntegerConstraint tmp1 = verify.that(123);
																					Reflection.clauseVisited();
		tmp1.isGreaterThan(100);
																					Reflection.clauseVisited();

																					
																					
																					Reflection.conversationLength(3);
		IntegerConstraint tmp2 = verify.that(123);
																					Reflection.clauseVisited();
		ReasonCapturer tmp3 = tmp2.isGreaterThan(100);
																					Reflection.clauseVisited();
		tmp3.because("blah blah");
																					Reflection.clauseVisited();
	}
	
	
	
	
	
	
	
	
	public interface Verify {
		IntegerConstraint that(int value);
	}
	
	public interface IntegerConstraint {
		ReasonCapturer isGreaterThan(int greaterThan);
	}
	
	public interface ReasonCapturer {
		void because(String reason);
	}
	
	
	
	
	
	
	
	
	

	public static class Implementation implements Verify, IntegerConstraint, ReasonCapturer {
		private int value;
		private int greaterThan;

		public IntegerConstraint that(int value) { 
			this.value = value;
			
			return this;
		}

		public ReasonCapturer isGreaterThan(int greaterThan) {
			if (Reflection.atEndOfConversation()) {
				Assert.assertTrue(value > greaterThan);

				// Nothing follows
				return null;
			}
			else {
				this.greaterThan = greaterThan;
				
				return this;
			}
		}

		public void because(String reason) {
			Assert.assertTrue(reason, value > greaterThan);
		}
	}
	
	
	
	
	
	public static class Reflection {
		private static int clausesLeft;

		public static void conversationLength(int length) {
			clausesLeft = length;
		}

		public static void clauseVisited() {
			clausesLeft--;
		}

		public static boolean atEndOfConversation() {
			return clausesLeft == 0;
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

	
	
	
	
	
	
	
	
}
